package com.caird.pmp.iot.message.impl;

import com.caird.common.utils.HexUtils;
import com.caird.pmp.iot.message.MessageBase;
import io.netty.buffer.ByteBuf;
import lombok.Data;


@Data
public class DeviceMessage01E0 extends MessageBase {

    public static final String REPORT_CODING[] = new String[]{
            "HXTAL", "LXTAL", "PVOL", "BVOL", "BAT", "NET", "GNSS", "NOR", "RS232", "IO", "CAN1", "CAN2", "CAN3", "CAN4", "BT", "TF", "USB"
    };

    public DeviceMessage01E0() {
        setId((short)0x01E0);
    }

    @Override
    public boolean decodeBody(ByteBuf raw) {

        if (getBodyLength() < 45)
            return false;

        //batch code
        byte[] bs = new byte[16];
        raw.readBytes(bs);
        batchCode = new String(bs);

        //MCU ID
        bs = new byte[24];
        raw.readBytes(bs);
        mcuId = new String(bs);

        //ICCID
        bs = new byte[20];
        raw.readBytes(bs);
        iccid = new String(bs);

        //测试报告
        bs = new byte[20];
        raw.readBytes(bs);
        for (int i=0; i<13; i++) {
            if (0x00 == bs[i]) {
                if (null == report)
                    report = REPORT_CODING[i];
                else
                    report += "," + REPORT_CODING[i];
            }
        }

        return true;
    }


    //批次码
    private String batchCode;

    //芯片ID
    private String mcuId;

    //iccid
    private String iccid;

    //测试报告
    private String report;

}
